package modelLayer;
import java.util.ArrayList;

/**
 * Liste over personer i programmet
 * og administrering af personer
 * 
 * 
 */
public class PersonContainer
{
    ArrayList<Person> people;
    private static PersonContainer instance;
    /**
     * Constructor for objects of class PersonContainer
     */
    private PersonContainer()
    {
        people = new ArrayList<Person>();
    }
    
    public static PersonContainer getInstance()
    {
        if(instance == null)
            instance = new PersonContainer();
        return instance;
    }
    
    public void addPerson(Person person)
    {
        people.add(person);
    }
    public Person findPerson(String phone)
    {
        Person personToReturn = null;
        boolean found = false;
        int i = 0;
        while(!found && i < people.size())
        {
            Person p = people.get(i);
            if(p.getPhone().equals(phone))
            {
                personToReturn = p;
                found = true;
            }
            i++;
        }
        return personToReturn;
    }
    
    public void removePerson(Person p)
    {
        people.remove(p);
    }
}